package com.shuiyun.jdbc.sharding;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * @author shuiyun
 */
public class OrderPreciseShardingTable implements PreciseShardingAlgorithm<Long> {

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
        Long value = shardingValue.getValue();
        value = value % 2 + 1;
        String tableName = shardingValue.getLogicTableName()+"_"+value;
        return availableTargetNames.contains(tableName)?tableName:null;
    }



}
